home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-08-10 | 5.0 KB | 167 lines | [TEXT/CWIE] |
- // ===========================================================================
- // CNetServerApp.cp ©1995-1998 Metrowerks Inc. All rights reserved.
- // ===========================================================================
- // This project is a simple shell to set up server connections. You can
- // test this program with the NetClient application.
-
- #include "CNetServerApp.h"
-
- #include <LGrowZone.h>
- #include <UDrawingState.h>
- #include <UMemoryMgr.h>
- #include <UModalDialogs.h>
- #include <URegistrar.h>
- #include <UDebugging.h>
- #include <UEnvironment.h>
-
- #include <LCaption.h>
- #include <LEditField.h>
- #include <LDialogBox.h>
- #include <LEditField.h>
- #include <LScroller.h>
- #include <LStdControl.h>
- #include <LTabGroup.h>
- #include <LThread.h>
- #include <UThread.h>
- #include <LCleanupTask.h>
-
- #include "CSimpleTCPServer.h"
- #include "CSimpleUDPServer.h"
- #include "CTerminalPane.h"
-
-
- const PP_PowerPlant::ResIDT ALRT_NoThreadManager = 1000;
- const PP_PowerPlant::ResIDT PPob_ServerSettings = 128;
-
-
- // ---------------------------------------------------------------------------
- // • main
- // ---------------------------------------------------------------------------
-
- int main()
- {
-
- SetDebugThrow_(PP_PowerPlant::debugAction_Alert); // Set Debugging options
- SetDebugSignal_(PP_PowerPlant::debugAction_Alert);
-
- PP_PowerPlant::InitializeHeap(15); // Initialize Memory Manager
- // Parameter is number of Master Pointer
- // blocks to allocate
-
- PP_PowerPlant::UQDGlobals::InitializeToolbox(&qd); // Initialize standard Toolbox managers
-
- // Check for Thread Manager.
- if ( !PP_PowerPlant::UEnvironment::HasFeature( PP_PowerPlant::env_HasThreadsManager ) ) {
- ::StopAlert(ALRT_NoThreadManager, nil);
- ::ExitToShell();
- }
-
- new PP_PowerPlant::LGrowZone(20000); // Install a GrowZone function to catch
- // low memory situations.
-
- // Run the application.
- new PP_PowerPlant::UMainThread;
-
- CNetServerApp theApp; // create instance of the application
-
- theApp.AddAttachment(new PP_PowerPlant::LYieldAttachment);
-
- theApp.Run();
-
- // Make sure async tasks get cleaned up. This call is VERY IMPORTANT.
- // (Note: LCleanupTask patches ExitToShell, so things get cleaned up
- // appropriately if you kill the application.)
- PP_PowerPlant::LCleanupTask::CleanUpAtExit();
-
- return 0;
- }
-
-
- // ---------------------------------------------------------------------------
- // • CNetServerApp
- // ---------------------------------------------------------------------------
- // Constructor
-
- CNetServerApp::CNetServerApp()
- : LDocApplication()
- {
- RegisterClass_(PP_PowerPlant::LCaption); // You must register each kind of
- RegisterClass_(PP_PowerPlant::LDialogBox); // PowerPlant classes that you use
- RegisterClass_(PP_PowerPlant::LEditField); // in your PPob resource.
- RegisterClass_(PP_PowerPlant::LScroller);
- RegisterClass_(PP_PowerPlant::LStdButton);
- RegisterClass_(PP_PowerPlant::LStdCheckBox);
- RegisterClass_(PP_PowerPlant::LTabGroup);
- RegisterClass_(PP_PowerPlant::LWindow);
-
- RegisterClass_(CTerminalPane);
-
- SetSleepTime(1); // increase responsiveness for Networking
- }
-
-
- // ---------------------------------------------------------------------------
- // • ~CNetServerApp
- // ---------------------------------------------------------------------------
- // Destructor
-
- CNetServerApp::~CNetServerApp()
- {
- }
-
-
- // ---------------------------------------------------------------------------
- // • MakeNewDocument
- // ---------------------------------------------------------------------------
- // What happens to File->New Session from the menu. Creates a settings dialog
- // then waits modally for a configuration. If completed, then opens a new session.
-
- PP_PowerPlant::LModelObject*
- CNetServerApp::MakeNewDocument()
- {
-
- // Show the configuration dialog.
- SInt32 port, count;
-
- PP_PowerPlant::StDialogHandler dialog(PPob_ServerSettings, this);
- Assert_(dialog.GetDialog() != nil);
- dialog.GetDialog()->Show();
-
- while (true) {
- PP_PowerPlant::MessageT hitMessage = dialog.DoDialog();
- if (hitMessage == PP_PowerPlant::msg_Cancel)
- return nil;
- else if (hitMessage == PP_PowerPlant::msg_OK)
- break;
- }
-
- // Get the user values from the dialog fields
- PP_PowerPlant::LEditField* countField = dynamic_cast<PP_PowerPlant::LEditField*>
- (dialog.GetDialog()->FindPaneByID('NUML'));
- ThrowIfNil_ (countField);
- count = countField->GetValue();
-
- PP_PowerPlant::LEditField* portField = dynamic_cast<PP_PowerPlant::LEditField*>
- (dialog.GetDialog()->FindPaneByID('PORT'));
- ThrowIfNil_ (portField);
- port = portField->GetValue();
-
- PP_PowerPlant::LStdCheckBox* udpOptionBox = dynamic_cast<PP_PowerPlant::LStdCheckBox*>
- (dialog.GetDialog()->FindPaneByID('_UDP'));
- ThrowIfNil_ (udpOptionBox);
- bool useUDP = udpOptionBox->GetValue();
-
- if (useUDP) {
- CSimpleUDPServer* theConnection = new CSimpleUDPServer(this);
- theConnection->WaitForUDPData(port);
- return theConnection;
-
- } else {
- CSimpleTCPServer* theConnection = new CSimpleTCPServer(this);
- theConnection->WaitForConnections(count, port);
- return theConnection;
- }
- }
-
-
-